package p1400;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author pengjz <br>
 * @version 1.0 <br>
 * @date 2022/2/14 11:20 <br>
 */
public class Leetcode_1497 {
    public boolean canArrange(int[] arr, int k) {
        Map<Integer, Integer> map = new HashMap<>();
        Set<Integer> set = new HashSet<>();
        // 1和4匹配之后，6和9也不影响匹配
        for (int i = 0; i < arr.length; i++) {
            if (!set.contains(i)) {
                for (int j = i + 1; j < arr.length; j++) {
                    if (!set.contains(j)) {
                        if ((arr[i] + arr[j]) % k == 0) {
                            set.add(i);
                            set.add(j);
                            break;
                        }
                    }
                }
            }
        }
        return set.size() == arr.length;
    }

    public static void main(String[] args) {
        final Leetcode_1497 l = new Leetcode_1497();
        System.out.println(
                l.canArrange(new int[]{75, 5, -5, 75, -2, -3, 88, 10, 10, 87}, 85)
        );

    }
}
